package event

import (
	"aquaman/app/infra/log"
	"github.com/gocraft/dbr/v2"
	"github.com/gocraft/health"
	"github.com/spf13/viper"
)

type LogWriter struct {
	logger log.Logger
}

func (l *LogWriter) Write(p []byte) (n int, err error) {
	l.logger.Info(string(p))
	return len(p), nil
}

func New(v *viper.Viper, logger log.Logger) dbr.EventReceiver {
	if v.GetBool("database.echo") {
		stream := health.NewStream()
		stream.AddSink(&health.WriterSink{Writer: &LogWriter{logger}})
		return stream
	} else {
		// TODO: metrics
		return nil
	}
}

